package com.lou1052.redis.jedis.factorybean;

import com.lou1052.redis.jedis.api.JedisApi;
import com.lou1052.redis.jedis.source.AbsJedisSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.JedisCommands;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * Created with IntelliJ IDEA.
 * User: liuqing
 * Date: 2015/10/15
 * Time: 22:31
 * To change this template use File | Settings | File Templates.
 */
public abstract class AbsJedisCommandsFactory<J extends JedisApi,S extends AbsJedisSource<J>> implements JedisCommandsFactory<J> {

    protected final S source;

    private final Class beanClass;

    protected final Logger logger = LoggerFactory.getLogger(getClass());

    public AbsJedisCommandsFactory(S source){
        this.source = source;
        Type genType = getClass().getGenericSuperclass();
        Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
        beanClass =  (Class)params[0];
    }

    @Override
    public final Class<?> getObjectType() {
        return beanClass;
    }

    @Override
    public final boolean isSingleton() {
        return true;
    }
}
